//
//  MyC.m
//  ShopDemo
//
//  Created by 飞扬的青春 on 2018/7/3.
//  Copyright © 2018年 飞扬的青春. All rights reserved.
//

#import "MyC.h"
#import "MyOrderView.h"
#import "MineOneCell.h"
#import "OrderController.h"
#import "LoginController.h"
#import "YHQController.h"
#import "AddManagerCon.h"
#import "ChangePassContr.h"
#import "ChagePersonCon.h"
#import "YHQController.h"
#import "MyPingLunCont.h"
#import "ShouCangViewCon.h"
#import "AFNetworking.h"
@interface MyC ()<UITableViewDelegate,UITableViewDataSource,UIActionSheetDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>


@property(nonatomic,strong)UITableView *listTableview;
@property(nonatomic,strong)NSArray *nameArray;
@property(nonatomic,strong)UILabel *titlab;
@property(nonatomic,strong)UIImageView *titimagevi;
@property(nonatomic,strong)NSArray *nameImageArray;


@end

@implementation MyC

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSString *strid = [UserDefault objectForKey:LogUserID];
    if (strid && strid.length > 0) {
        self.nameArray = @[@"收货地址管理",@"我的评论",@"收藏",@"优惠券",@"修改个人信息",@"修改密码",@"联系我们 0371-88911111",@"检查更新",@"退出"];
        self.nameImageArray = @[@"location_icon.png",@"center_icon_order_all.png",@"icon_collection_ed.png",@"wode_cupon.png",@"changeuserdata_icon.png",@"changepsd_icon.png",@"phonecall_icon.png",@"check_new_icon.png",@"exit_icon.png"];
    }else {
        self.nameArray = @[@"收货地址管理",@"我的评论",@"收藏",@"优惠券",@"修改个人信息",@"修改密码",@"联系我们 0371-88911111",@"检查更新"];
        self.nameImageArray = @[@"location_icon.png",@"center_icon_order_all.png",@"icon_collection_ed.png",@"wode_cupon.png",@"changeuserdata_icon.png",@"changepsd_icon.png",@"phonecall_icon.png",@"check_new_icon.png"];
    }
    if (self.listTableview) {
        [self.listTableview reloadData];
    }
    NSString *username = [UserDefault objectForKey:LogRealName];
    if (username && username.length > 0) {
        self.titlab.text = [NSString stringWithFormat:@"%@",username];
        [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:[UserDefault objectForKey:LogUserSFID]]];
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatTableviewMethod];
    
}

-(void)creatTableviewMethod{
    self.listTableview = [[UITableView alloc]initWithFrame:CGRectMake(0,0, kScreenWidth, kScreenHeight - 120) style:UITableViewStylePlain];
    self.listTableview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.listTableview];
    if (kScreenHeight == 812) {
        self.listTableview.sd_layout
        .bottomSpaceToView(self.view, 34);
    }
        self.listTableview.dataSource = self;
        self.listTableview.delegate = self;
        [self.listTableview registerClass:[MineOneCell class] forCellReuseIdentifier:@"onecell"];
    //分隔线
//        self.listTableview.separatorStyle = UITableViewCellAccessoryNone;
    //去掉尾部多余的空白
    [self.listTableview setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
    
    UIView *headerview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 200*kJLXWidthScale + 120*kJLXWidthScale)];
    headerview.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.5];
    self.listTableview.tableHeaderView = headerview;
    UIImageView *imagevi = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 200*kJLXWidthScale)];
    imagevi.image = [UIImage imageNamed:@"ImageMine.jpg"];
    imagevi.userInteractionEnabled = YES;

    self.titimagevi = [UIImageView new];
    self.titimagevi.image = [UIImage imageNamed:@"ImageTit.png"];
    self.titimagevi.backgroundColor = [UIColor whiteColor];
    self.titimagevi.layer.masksToBounds = YES;
    self.titimagevi.layer.cornerRadius = 80*kJLXWidthScale/2;
    [imagevi addSubview:self.titimagevi];
    self.titimagevi.sd_layout
    .leftSpaceToView(imagevi, 40*kJLXWidthScale)
    .heightIs(80*kJLXWidthScale)
    .widthIs(80*kJLXWidthScale)
    .centerYEqualToView(imagevi);
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(LoginAndRegisterTap:)];
    self.titimagevi.userInteractionEnabled = YES;
    [self.titimagevi addGestureRecognizer:tap];
    [headerview addSubview:imagevi];
    
    UILabel *titlab = [UILabel new];
    NSString *usrename = [UserDefault objectForKey:LogRealName];
    if (usrename && usrename.length > 0) {
         titlab.text = usrename;
    }else{
        titlab.text = @"未登录";
         self.titimagevi.image = [UIImage imageNamed:@"ImageTit.png"];
    }
    self.titlab = titlab;
    titlab.font = [UIFont systemFontOfSize:20*kJLXWidthScale];
    titlab.textColor = [UIColor whiteColor];
    [imagevi addSubview:titlab];
    titlab.sd_layout
    .centerYEqualToView(self.titimagevi)
    .leftSpaceToView(self.titimagevi, 8*kJLXWidthScale)
    .heightIs(40*kJLXWidthScale)
    .rightSpaceToView(imagevi, 80*kJLXWidthScale);
    
    MineButton *righbtn = [MineButton buttonWithType:UIButtonTypeCustom];
    [righbtn setImage:[UIImage imageNamed:@"ImageRight.png"] forState:UIControlStateNormal];
    [righbtn addTarget:self action:@selector(LoginAndRegisterButton:) forControlEvents:UIControlEventTouchUpInside];
    righbtn.backgroundColor = [UIColor clearColor];
    [imagevi addSubview:righbtn];
    righbtn.sd_layout
    .centerYEqualToView(titlab)
    .rightSpaceToView(imagevi, 10*kJLXWidthScale)
    .heightIs(30*kJLXWidthScale)
    .widthIs(30*kJLXWidthScale);
    
    MyOrderView *orderview = [MyOrderView new];
    orderview.backgroundColor = [UIColor whiteColor];
    [headerview addSubview:orderview];
    orderview.sd_layout
    .topSpaceToView(imagevi, 5*kJLXWidthScale)
    .leftSpaceToView(headerview, 0)
    .heightIs(110*kJLXWidthScale)
    .widthIs(kScreenWidth);
    
    [orderview.oneBtn addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [orderview.twoBtn addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [orderview.thirdBtn addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [orderview.fourBtn addTarget:self action:@selector(orderButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)orderButtonAction:(MineButton *)sender{
    NSString *usrename = [UserDefault objectForKey:LogRealName];
    if (usrename && usrename.length > 0) {
        OrderController *orderVC = [[OrderController alloc]init];
        orderVC.navigationItem.title = sender.minlab.text;
        orderVC.hidesBottomBarWhenPushed = YES;
        if ([sender.minlab.text isEqualToString:@"待支付"]) {
            orderVC.strurl = [NSString stringWithFormat:@"/dashop/order/app/list.do?username=%@&status=0&CurrentPage=1",[UserDefault objectForKey:LogUserName]];
        }else if ([sender.minlab.text isEqualToString:@"待发货"]){
            orderVC.strurl = [NSString stringWithFormat:@"/dashop/order/app/list.do?username=%@&status=1&CurrentPage=1",[UserDefault objectForKey:LogUserName]];
        }else if ([sender.minlab.text isEqualToString:@"待收货"]){
            orderVC.strurl = [NSString stringWithFormat:@"/dashop/order/app/list.do?username=%@&status=2&CurrentPage=1",[UserDefault objectForKey:LogUserName]];
        }else if ([sender.minlab.text isEqualToString:@"待评价"]){
            orderVC.strurl = [NSString stringWithFormat:@"/dashop/order/app/list.do?username=%@&status=5&CurrentPage=1",[UserDefault objectForKey:LogUserName]];
        }
        [self.navigationController pushViewController:orderVC animated:YES];
    }else{
        LoginController *loginVC = [[LoginController alloc]init];
        loginVC.logBlock = ^(NSDictionary *logdic) {
            self.titlab.text = [NSString stringWithFormat:@"%@",logdic[@"NAME"]];
            if ([logdic[@"SFID"] hasPrefix:@"http"]) {
                [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:logdic[@"SFID"]]];
            }else{
                NSString *urlstr = [NSString stringWithFormat:@"/dashop/%@",logdic[@"SFID"]];
                NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
                [SDWebImageDownloader.sharedDownloader setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
                [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:endstr]];
            }
        };
        loginVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginVC animated:YES];
    }
}

-(void)LoginAndRegisterTap:(UITapGestureRecognizer *)tap{
    if ([self.titlab.text isEqualToString:@"未登录"]) {
        LoginController *loginVC = [[LoginController alloc]init];
        loginVC.logBlock = ^(NSDictionary *logdic) {
            self.titlab.text = [NSString stringWithFormat:@"%@",logdic[@"NAME"]];
            if ([logdic[@"SFID"] hasPrefix:@"http"]) {
                [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:logdic[@"SFID"]]];
            }else{
                NSString *urlstr = [NSString stringWithFormat:@"/dashop/%@",logdic[@"SFID"]];
                NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
                [SDWebImageDownloader.sharedDownloader setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
                [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:endstr]];
            }
        };
        loginVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginVC animated:YES];
    }else{
        //上传头像
        [self.view endEditing:YES];
        UIActionSheet *sheet;
        // 判断是否支持相机
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
            
        {
            sheet  = [[UIActionSheet alloc] initWithTitle:@"选择" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"取消" otherButtonTitles:@"拍照",@"从相册选择", nil];
        }else{
            
            sheet = [[UIActionSheet alloc] initWithTitle:@"选择" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"取消" otherButtonTitles:@"从相册选择", nil];
        }
        
        sheet.tag = 255;
        [sheet showInView:self.view];
    }
}


-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (actionSheet.tag == 255) {
        NSUInteger sourceType = 0;
        // 判断是否支持相机
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            
            switch (buttonIndex) {
                case 0:
                    // 取消
                    return;
                case 1:
                    // 相机
                    sourceType = UIImagePickerControllerSourceTypeCamera;
                    break;
                case 2:
                    // 相册
                    sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                    break;
            }
        }else {
            if (buttonIndex == 0) {
                return;
            } else {
                sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
            }
        }
        // 跳转到相机或相册页面
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = self;
        imagePickerController.allowsEditing = YES;
        imagePickerController.sourceType = sourceType;
        [self presentViewController:imagePickerController animated:YES completion:^{}];
        
    }
}

#pragma mark - image picker delegte
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    /* 此处info 有六个值
     * UIImagePickerControllerMediaType; // an NSString UTTypeImage)
     * UIImagePickerControllerOriginalImage;  // a UIImage 原始图片
     * UIImagePickerControllerEditedImage;    // a UIImage 裁剪后图片
     * UIImagePickerControllerCropRect;       // an NSValue (CGRect)
     * UIImagePickerControllerMediaURL;       // an NSURL
     * UIImagePickerControllerReferenceURL    // an NSURL that references an asset in the AssetsLibrary framework
     * UIImagePickerControllerMediaMetadata    // an NSDictionary containing metadata from a captured photo
     */
    // 保存图片至本地，方法见下文
    //    NSLog(@"img = %@",image);
    image = [self compressImage:image toMaxFileSize:0.2];
    [self titPhoneImage:image];
}



-(void)titPhoneImage:(UIImage *)image{
    NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:@"/dashop/happuser/app/uploadH.do"];
    NSDictionary *dic = @{@"USER_ID":[UserDefault objectForKey:LogUserID]};
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //ContentType设置
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",@"image/jpeg",@"image/png",@"application/octet-stream",@"text/json",nil];
    manager.requestSerializer= [AFHTTPRequestSerializer serializer];
    manager.responseSerializer= [AFHTTPResponseSerializer serializer];
    [manager POST:endstr parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        //压缩图片像素
        NSData *titdata = UIImagePNGRepresentation(image);
        //上传的参数(上传图片，以文件流的格式)
        [formData appendPartWithFileData:titdata
                                    name:@"HEADIMG"
                                fileName:@"iOS.png"
                                mimeType:@"image/png"];
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSString *jsonstr = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSDictionary *dic = [MethodClass dictionaryWithJsonString:jsonstr];
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
        if ([dic[@"RESULT"] integerValue] == 1) {
                self.titimagevi.image = image;
        }else{
            [self alerWithMessage:dic[@"MESSAGE"]];
        }
        }];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}



- (UIImage *)compressImage:(UIImage *)image toMaxFileSize:(NSInteger)maxFileSize {
    CGFloat compression = 0.9f;
    CGFloat maxCompression = 0.1f;
    NSData *imageData = UIImageJPEGRepresentation(image, compression);
    while ([imageData length] > maxFileSize && compression > maxCompression) {
        compression -= 0.1;
        imageData = UIImageJPEGRepresentation(image, compression);
    }
    
    UIImage *compressedImage = [UIImage imageWithData:imageData];
    return compressedImage;
}



-(void)LoginAndRegisterButton:(MineButton *)sender{
    if ([self.titlab.text isEqualToString:@"未登录"]) {
        LoginController *loginVC = [[LoginController alloc]init];
        loginVC.logBlock = ^(NSDictionary *logdic) {
            self.titlab.text = [NSString stringWithFormat:@"%@",logdic[@"NAME"]];
            if ([logdic[@"SFID"] hasPrefix:@"http"]) {
                [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:logdic[@"SFID"]]];
            }else{
                NSString *urlstr = [NSString stringWithFormat:@"/dashop/%@",logdic[@"SFID"]];
                NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
                [SDWebImageDownloader.sharedDownloader setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
                [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:endstr]];
            }
            
        };
        loginVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginVC animated:YES];
    }else{
        //账号注销
        KMLog(@"点击了账户注销cell");
        //注销账户就是将本地沙河中的的用户信息移除
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您确定要退出当前账号吗?" preferredStyle:(UIAlertControllerStyleAlert)];
        //确定事件
        UIAlertAction *sureActioin = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            //从沙盒中移除密码
            [UserDefault removeObjectForKey:LogPassWord];
            [UserDefault removeObjectForKey:LogUserName];
            [UserDefault removeObjectForKey:LogRealName];
            [UserDefault removeObjectForKey:LogUserID];
            [UserDefault removeObjectForKey:LogUserSFID];
            [self.listTableview reloadData];
            self.titlab.text = @"未登录";
            self.titimagevi.image = [UIImage imageNamed:@"ImageTit.png"];
            //移除密码后，跳转到登录界动画
            LoginController *loginVC = [[LoginController alloc] init];
            loginVC.logBlock = ^(NSDictionary *logdic) {
                self.titlab.text = [NSString stringWithFormat:@"%@",logdic[@"NAME"]];
                if ([logdic[@"SFID"] hasPrefix:@"http"]) {
                    [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:logdic[@"SFID"]]];
                }else{
                    NSString *urlstr = [NSString stringWithFormat:@"/dashop/%@",logdic[@"SFID"]];
                    NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
                    [SDWebImageDownloader.sharedDownloader setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
                    [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:endstr]];
                }
            };
            loginVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:loginVC animated:YES];
        }];
        //取消事件
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alertVC addAction:sureActioin];
        [alertVC addAction:cancelAction];
        [self.navigationController presentViewController:alertVC animated:YES completion:nil];
    }
}








#pragma mark --UITableViewDelegate,UITableViewDataSource--


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.nameArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MineOneCell *cell = [tableView dequeueReusableCellWithIdentifier:@"onecell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.titlab.text = self.nameArray[indexPath.row];
    cell.titimageview.image = [UIImage imageNamed:self.nameImageArray[indexPath.row]];
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40*kJLXWidthScale;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *usrename = [UserDefault objectForKey:LogRealName];
    if (usrename && usrename.length > 0) {
        NSString *str = self.nameArray[indexPath.row];
        if ([str isEqualToString:@"优惠券"]) {
            YHQController *yhqVC = [[YHQController alloc]init];
            yhqVC.navigationItem.title = @"优惠券";
            yhqVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:yhqVC animated:YES];
        }else if ([str isEqualToString:@"收货地址管理"]){
            AddManagerCon *addVC = [[AddManagerCon alloc]init];
            addVC.navigationItem.title = @"收货地址管理";
            addVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:addVC animated:YES];
        }else if ([str isEqualToString:@"修改密码"]){
            ChangePassContr *chVC = [[ChangePassContr alloc]init];
            chVC.navigationItem.title = @"修改密码";
            chVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:chVC animated:YES];
        }else if ([str isEqualToString:@"修改个人信息"]){
            ChagePersonCon *chVC = [[ChagePersonCon alloc]init];
            chVC.navigationItem.title = @"修改个人信息";
            chVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:chVC animated:YES];
        }else if ([str isEqualToString:@"我的评论"]){
            MyPingLunCont *plvc = [[MyPingLunCont alloc]init];
            plvc.navigationItem.title = @"我的评论";
            plvc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:plvc animated:YES];
        }else if ([str isEqualToString:@"联系我们 0371-88911111"]){
            NSString *str = [NSString stringWithFormat:@"telprompt://0371-88911111"];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        }else if ([str isEqualToString:@"检查更新"]){
//            [self alerWithMessage:@"已升级到最新版本"];
            NSString *appurl = @"https://itunes.apple.com/cn/app/动情/id1428303575?mt=8";
            NSString  *newappurl = [appurl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:newappurl]];
        }else if ([str isEqualToString:@"收藏"]){
            ShouCangViewCon *scVC = [[ShouCangViewCon alloc]init];
            scVC.navigationItem.title = @"收藏";
            scVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:scVC animated:YES];
        }else if ([str isEqualToString:@"退出"]){
            //注销账户就是将本地沙河中的的用户信息移除
            UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您确定要退出当前账号吗?" preferredStyle:(UIAlertControllerStyleAlert)];
            //确定事件
            UIAlertAction *sureActioin = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                //从沙盒中移除密码
                [UserDefault removeObjectForKey:LogPassWord];
                [UserDefault removeObjectForKey:LogUserName];
                [UserDefault removeObjectForKey:LogRealName];
                [UserDefault removeObjectForKey:LogUserID];
                [UserDefault removeObjectForKey:LogUserSFID];
                [self.listTableview reloadData];
                self.titlab.text = @"未登录";
                self.titimagevi.image = [UIImage imageNamed:@"ImageTit.png"];
                //移除密码后，跳转到登录界动画
                LoginController *loginVC = [[LoginController alloc] init];
                loginVC.logBlock = ^(NSDictionary *logdic) {
                    self.titlab.text = [NSString stringWithFormat:@"%@",logdic[@"NAME"]];
                    if ([logdic[@"SFID"] hasPrefix:@"http"]) {
                        [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:logdic[@"SFID"]]];
                    }else{
                        NSString *urlstr = [NSString stringWithFormat:@"/dashop/%@",logdic[@"SFID"]];
                        NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
                        [SDWebImageDownloader.sharedDownloader setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
                        [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:endstr]];
                    }
                };
                loginVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:loginVC animated:YES];
            }];
            //取消事件
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            [alertVC addAction:sureActioin];
            [alertVC addAction:cancelAction];
            [self.navigationController presentViewController:alertVC animated:YES completion:nil];
        }
    }else{
        LoginController *loginVC = [[LoginController alloc]init];
        loginVC.logBlock = ^(NSDictionary *logdic) {
            self.titlab.text = [NSString stringWithFormat:@"%@",logdic[@"NAME"]];
            if ([logdic[@"SFID"] hasPrefix:@"http"]) {
                [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:logdic[@"SFID"]]];
            }else{
                NSString *urlstr = [NSString stringWithFormat:@"/dashop/%@",logdic[@"SFID"]];
                NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
                [SDWebImageDownloader.sharedDownloader setValue:@"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" forHTTPHeaderField:@"Accept"];
                [self.titimagevi sd_setImageWithURL:[NSURL URLWithString:endstr]];
            }
        };
        loginVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginVC animated:YES];
    }
    
    

}

//封装提示框方法
-(void)alerWithMessage:(NSString *)msg{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alert animated:YES completion:^{
        //延迟1秒自动消失
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [alert dismissViewControllerAnimated:YES completion:nil];
        });
    }];
}


@end

